home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 January - Disc 2
/
Macworld (1999-01) (Disk 2).dmg
/
Serious Demos
/
Symbolic Composer 4.2
/
Environment
/
Projects
/
Neurons
/
Random Rule Neurons
< prev
next >
Wrap
Lisp/Scheme
|
1998-10-26
|
4KB
|
109 lines
; Random Rule Oscillator 'noisy neuron'
; Here a random rule oscillator is defined, and a couple of
; other neurons for further generating 2nd and 3rd melody lines.
; Use this as guidelines on how to define neural oscillators.
; Use melody,1 melody2 and melody3 to define instrument symbols.
; Perhaps the simpliest way to make a permanently oscillating
; neuron is to use random rules, like in the following. When
; experimenting with different pick-random values, or when
; extending the rules, keep in mind that the outputs must fall
; in the range of input rules can handle, and if not then
; otherwise option must return the output in the input range.
(defun feedback-neuron (name n inputs)
(let ((out nil) (collect nil))
(dotimes (i n)
(setq out (apply 'run-neuron (append (list name) inputs)))
(push out collect)
(setq inputs (append (cdr inputs) (list out))))
(nreverse collect)))
(defun pack-name (a b)
(compress (append (explode a) '(-) (explode b))))
(defun seq (&optional name sequence)
(let ((out nil)
(counter nil))
(cond (sequence
(cond ((equal sequence :reset)
(set (pack-name 'counter name) 0))
(t (set (pack-name 'seq name) (vector-to-list sequence))
(set (pack-name 'counter name) 0)))
t)
(t (setq counter (eval (pack-name 'counter name)))
(setq out (nth (mod counter (length (eval (pack-name 'seq name))))
(eval (pack-name 'seq name))))
(setq counter (1+ counter))
(set (pack-name 'counter name) counter)
out))))
(def-neuron random-rule
(in 1 'a) (pick-random '(a b))
(in 1 'b) (pick-random '(-b -c))
(otherwise (pick-random '(a b)))
)
; Examine this in the visualizer. Use flatten to get rid of
; the sublists. The oscillations have quite interesting look.
; (flatten (feedback-neuron 'random-rule 10 '((a b c))))
; --> (b -c b -b b -c b -b b -b a -b a b a b -c a -c b a b -b a -c a a a a a)
; To make rests, try the following:
(def-neuron random-rule
(in 1 'a) (pick-random '(a b))
(in 1 'b) (pick-random '(-b =))
(otherwise (pick-random '(a b)))
)
; (flatten (feedback-neuron 'random-rule 10 '((a b c))))
; --> (a = b a b = b -b b -b a = b b a = -b b b b = = = a b a a = b a)
; Parallel Neural Lines
; Random-rule neuron can be used as a 'clock signal' to drive
; the other neurons. This is accomplished in this way:
(setq melody1 (flatten (feedback-neuron 'random-rule 10 '((a b c)))))
; --> (a -b b b b = = -b a b a b = a -b b a b -b b -b b -b b -b a -b b a a)
; Now, we want to add 2 more parallel lines to this neural pattern,
; so that all of the patterns obey a consistent set of rules. First
; generate the second line. This neuron finds series of aa, bb and
; ab. There is some randomness if these patterns are not found, and
; the output is picked random. Notice the multiple rests = = =. This
; ables to determine that the rests have 3/4 possibility to get
; selected resulting in a pattern with more rests.
(def-neuron second-line
(and (in 1 'a) (in 1 'a -1)) 'a
(and (in 1 'b) (in 1 'b -1)) 'b
(and (in 1 'a) (in 1 'b -1)) 'c
(otherwise (pick-random '(= = = -b)))
)
(setq melody2 (run-neuron 'second-line melody1))
; To add third line define one more neuron, and make it examine what
; is happening in both within each input line, and what is happening
; in parallel between the inputs.
(def-neuron third-line
(and (in 1 'b) (in 2 'b)) 'a
(and (in 1 'a) (in 2 'a)) 'b
(or (and (in 1 'b) (in 1 '-b -1))
(and (in 1 '-b) (in 1 'b -1))) (pick-random '(c d))
(otherwise (pick-random '(=)))
)
(setq melody3 (run-neuron 'third-line melody1 melody2))
; Use melody1, melody2, melody3 to define instruments. Redefine
; neuron rules to get more specific behaviour. The example shows
; just the basic principles of constructing neurons.
; here comes your code
; kjhkjhkjhkjhkjhkjhkjhkjhkjh